package com.rr.easy;

import com.rr.entity.TreeNode;

/**
 * @author zhuangcanrun
 * @Date 2022/05/04/14:17
 * @description
 **/

public class MinDepth {

    private int minDepth = Integer.MAX_VALUE;

    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        justDoIt(root, 1);
        return minDepth;
    }

    private void justDoIt(TreeNode node, int currentDepth) {
        if (node != null && node.left==null && node.right == null) {
            minDepth = Math.min(currentDepth, minDepth);
            return;
        }
        if (node == null) {
            return;
        }
        justDoIt(node.left, currentDepth + 1);
        justDoIt(node.right, currentDepth + 1);
    }
}
